<?php
/**
 * Created by Zend Studio.
 * User: FDG348
 * Date: 2018/4/8
 * Time: 9:13
 */
namespace backend\models;

use Yii;
use yii\db\ActiveRecord;

class GoodsNavigationIdentificationrelationEdit extends ActiveRecord{
    public static function tableName(){
        return '{{%goods_navigation_identification_relation_edit}}';
    }

    /**
     * @获取创建人
     */
    public function getCreator(){
        $userInfo = \common\helps\tools::getloginUserInfo();
        if($userInfo){
            $userName = $userInfo->userName;
        }else{
            $userName = '';
        }
        return $userName;
    }
    
    public function publishNav($main_goods_id){
        $is_complete = true;
        $goods_nav_edit = $this->find()->where(['main_goods_id'=>$main_goods_id])->asArray()->all();
        $del_nav = GoodsNavigationIdentificationrelation::deleteAll(['main_goods_id'=>$main_goods_id]);
        if (is_array($goods_nav_edit) && count($goods_nav_edit) > 0)foreach ($goods_nav_edit as $edit){
            unset($edit['id']);
            $edit['creator'] = $this->getCreator();
            $edit['create_time'] = date('Y-m-d H:i:s');
            $edit['editor'] = $this->getCreator();
            $edit['edit_time'] = date('Y-m-d H:i:s');
            $res = Yii::$app->db->createCommand()->insert('j_goods_navigation_identification_relation',$edit)->execute();
            if(!$res){
                return false;
            }
        }
    }
}